/*
 *  Class contains main methods for creating and basic
 *  mathematical manipulation with interval matrix 
 */

package intervalMath;

/**
 *
 * @author Vera Morozova
 */
public class MatrixIntervalArithmetic {
    private int lines;
    private int columns;
    private IntervalArithmetic[][] matrix;
    
    public IntervalArithmetic[][] getMatrix() {
        return matrix;
    }

    public void setMatrix(IntervalArithmetic[][] matrix) {
        this.matrix = matrix;
    }

    public int getColumns() {
        return columns;
    }

    public void setColumns(int columns) {
        this.columns = columns;
    }

    public int getLines() {
        return lines;
    }

    public void setLines(int lines) {
        this.lines = lines;
    }
    public MatrixIntervalArithmetic(int lines, int columns, IntervalArithmetic[][] matrix){
        this.lines = lines;
        this.columns = columns;
        this.matrix = matrix;
    }
    public MatrixIntervalArithmetic (){
        this.lines = 0;
        this.columns = 0;
        this.matrix = null;
    }

    public MatrixIntervalArithmetic add(MatrixIntervalArithmetic b) throws IntervalException{
        if (this.getLines()!= b.getLines() || this.getColumns()!= b.getColumns())
            throw new IntervalException("Matrixes have different dimension!");
        MatrixIntervalArithmetic result = new MatrixIntervalArithmetic();
        result.setLines(b.getLines());
        result.setColumns(b.getColumns());
        for(int i=0; i<this.getLines();i++){
            for(int j=0; j<this.getColumns(); j++){
                result.getMatrix()[i][j] = this.getMatrix()[i][j].add(b.getMatrix()[i][j]);
            }
        }
        return result;
    }

    public MatrixIntervalArithmetic sub(MatrixIntervalArithmetic b) throws IntervalException{
        if (this.getLines()!= b.getLines() || this.getColumns()!= b.getColumns())
            throw new IntervalException("Matrixes have different dimension!");
        MatrixIntervalArithmetic result = new MatrixIntervalArithmetic();
        result.setLines(b.getLines());
        result.setColumns(b.getColumns());
        for(int i=0; i<this.getLines();i++){
            for(int j=0; j<this.getColumns(); j++){
                result.getMatrix()[i][j] = this.getMatrix()[i][j].sub(b.getMatrix()[i][j]);
            }
        }
        return result;
    }

    public MatrixIntervalArithmetic mult(MatrixIntervalArithmetic b) throws IntervalException{
        if (this.getColumns()!= b.getLines())
            throw new IntervalException("Matrixes have wrong sizes!");
        MatrixIntervalArithmetic result = new MatrixIntervalArithmetic();
        result.setLines(this.getLines());
        result.setColumns(b.getColumns());
        for(int i=0; i<this.getLines();i++){
            for(int j=0; j<this.getColumns(); j++){
                for(int k=0; k<this.getColumns();k++)
                    result.getMatrix()[i][j] = result.getMatrix()[i][j].add(this.getMatrix()[i][k].mult(b.getMatrix()[k][j]));
            }
        }
        return result;
    }
}
